package org.uoss.applications.framework.configuration;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class AppSystemConfigurationImpl implements IAppSystemConfiguration {

	protected Properties properties = null;
	
	public AppSystemConfigurationImpl(){
		this.loadLocalConfiguration();
	}
	
	public void loadLocalConfiguration(){
		InputStream is = null;
		try {
			is = this.getClass().getResourceAsStream("/META-INF/Local-Application-Context.properties");
			if(is!=null){
				this.properties = new Properties();
				this.properties.load(is);
			}
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally{
			if(is==null||this.properties.isEmpty()){
				this.loadDefaultConfiguration();
			}
		}
	}
	
	protected void loadDefaultConfiguration(){
		try {
			InputStream is = this.getClass().getResourceAsStream("/META-INF/Application-Context.properties");
			this.properties = new Properties();
			this.properties.load(is);
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public String getSystemProperty(String propKey,String defaultValue){
		if(this.properties==null){
			return null;
		}
		else{
			return this.properties.getProperty(propKey, defaultValue);
		}
	}
}
